package com.mc.cloud.mall.categoryProduct.controller;

import com.github.pagehelper.PageInfo;
import com.mc.cloud.mall.categoryProduct.model.pojo.Product;
import com.mc.cloud.mall.categoryProduct.model.vo.ProductList;
import com.mc.cloud.mall.categoryProduct.service.UserProductService;
import com.mc.cloud.mall.common.common.MallRestResponse;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName UserProductController
 * @Author MC
 * @Date 2020/11/5 17:38
 * @Version 1.0
 **/
@Controller
public class UserProductController {
    
    @Autowired
    UserProductService userProductService;
    
    /*public MallRestResponse productList(){
    
    }*/
    
    /**
     * 商品详情
     * @param id
     * @return
     */
    @ApiOperation("商品详情")
    @GetMapping("/product/detail")
    @ResponseBody
    public MallRestResponse productDetail(@RequestParam Integer id){
        
        Product product = userProductService.productDetail(id);
        
        return MallRestResponse.success(product);
    }
    
    /**
     * 商品列表
     * @return
     */
    @ApiOperation("商品列表")
    @GetMapping("/product/list")
    @ResponseBody
    public MallRestResponse list(ProductList productList){
    
        PageInfo list = userProductService.list(productList);
        return MallRestResponse.success(list);
    
    }
    
    @ApiOperation("商品详情feign")
    @GetMapping("/product/detailForFeign")
    @ResponseBody
    public Product productDetailForFeign(@RequestParam Integer id){
        
        Product product = userProductService.productDetail(id);
        
        return product;
    }
    
    @ApiOperation("更新商品feign")
    @PostMapping("/product/updateProductForFeign")
    @ResponseBody
    public void updateProductForFeign(@RequestParam Integer productId,@RequestParam Integer stock){
        
        userProductService.updateProductForFeign(productId,stock);
        
    }
}
